﻿using NMoq.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq.Expressions;
using System.Reflection;

namespace NMoq.Core.UnitTest
{
    
    
    /// <summary>
    ///This is a test class for MockHelperTest and is intended
    ///to contain all MockHelperTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MockHelperTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for MockMethod
        ///</summary>
        [TestMethod ]
        public void MockServiceTestHelper()
        {
            CustomerIE cc = new CustomerIE();
            cc.Name = "adf";

            CustomerIE c2 = new CustomerIE() {Name ="d" };

            MethodInfo methodInfo1 = cc.GetType().GetMethod("SetName");
            MethodInfo methodInfo2 = c2.GetType().GetMethod("SetName");
 
        }

        [TestMethod()]
        public void MockServiceTest()
        {
            //MockHelper.MockFuncMethod  <CustomerIE, string>(d => d.Remove(2));
            //MockHelper.MockFuncMethod<CustomerIE, string, IDataProvider>(d => d.Remove(3), (m, d) => { d.Write(m, ""); });

            MockHelper.MockActionMethod<CustomerIE>(d => d.SetName("asdfsad"));

            DelegateDataProvider dataProvider = new DelegateDataProvider();  
            

            MockHelper.MockActionMethod<CustomerIE, IVerifier>(d => d.SetName("asdfasdfasdf"),
                    new DefaultVerifier() {  VerifyDelegate = args=>args[0].ToString ().Length <6}
                    );

            CustomerIE customer = MockHelper.GetMock<CustomerIE>().ProxiedTarget ;
            string value ="asdfasdfasdf";
            customer.SetName("asdfasdfasdf");
            customer.Name = value;
            string actual = customer.Remove(2);
            actual = customer.Remove(3);
            string expected = value.Remove(2);

            
        }

        [TestMethod ]
        public void MockClassTest()
        {
            MockHelper.MockClass<CustomerIE>();
        }
    }

    public class CustomerIE:MarshalByRefObject 
    {
        public string Name
        { get; set; }

        public string Remove(int index)
        {
            return Name.Remove(index);
        }

        public void SetName(string name)
        {
            Name = name;
        }
    }
}
